package playsound;

import java.io.IOException;
import java.io.InputStream;

import javax.sound.sampled.*;

/**
 * 麦叔HowTo #1 - 如何用Java播放背景音乐
 * @author 麦叔
 */
public class PlaySound {

	public static void main(String[] args) {
		try {
			Clip bgm = AudioSystem.getClip();
			InputStream is = PlaySound.class.getClassLoader().getResourceAsStream("sound/bgm.wav");
			AudioInputStream ais = AudioSystem.getAudioInputStream(is);
			bgm.open(ais);
			bgm.start();
			bgm.loop(Clip.LOOP_CONTINUOUSLY);
			while(true) {}
		} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
			e.printStackTrace();
		}
		

	}

}
